package com.koron.css2.projectCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.projectCenter.bean.PjUseMatrBean;
import com.koron.css2.projectCenter.bean.query.PjUseMatrQueryBean;
import com.koron.css2.projectCenter.mapper.PjUseMatrMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

/**
 * 用料及领料列表
 * @author 许海宜
 * 2020年3月31日
 */
public class PjUseMatrList implements ServerInterface {

	@Override
	@SuppressWarnings("rawtypes")
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		try {
			//将入参转换
			PjUseMatrQueryBean bean = JsonUtils.objectToPojo(req.getData(), PjUseMatrQueryBean.class);
			if(StringUtils.isBlank(bean.getPjId())) {
				return MessageBean.create(Constant.NOT_NULL, "单据不存在", null);
			}
			//获取Mapper实例
			PjUseMatrMapper mapper = factory.getMapper(PjUseMatrMapper.class);			
			//执行SQL
			List<PjUseMatrBean> list = mapper.select(bean.getPjId(), bean.getType());		
			for (PjUseMatrBean p : list) {
				p.setMatrMoney(p.getMatrPrice()*p.getMatrNum());
			}
			//输出结果
			MessageBean<List> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", List.class);
			info.setData(list);
			return info;
		} catch (Exception e) {
			logger.error("用水咨询-多水表列表查询失败"+e.getMessage(), e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "查询失败", null);
		}
	}

	
}
